<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

  

    nav {
      position: relative;
      display: flex;
    }

    nav a {
      position: relative;
      margin: 0 20px;
      font-size: 20px;
      color: pink;
      text-decoration: none;
    }

    nav #marker {
      position: absolute;
      height: 4px;
      width: 10%;
      background-color: red;
      left: 20px;
      bottom: -8px;
      transition: .5s;
      border-radius: 4px;
    }
  </style>
</head>

<body>
  <nav>
    <div id="marker"></div>
    <a href="#">Home</a>
    <a href="#">About</a>
    <a href="#">Services</a>
    <a href="#">Portfolio</a>
    <a href="#">Team</a>
    <a href="#">Contact</a>
  </nav>
  <script>
    var marker = document.querySelector('#marker')
    var dao = document.querySelectorAll('a')
    console.log(marker, 'marker');

    function indicator(e) {
      marker.style.left = e.offsetLeft + 'px'
      marker.style.width = e.offsetWidth + 'px'
    }

    dao.forEach(link => {
      link.addEventListener('click', e => {
        indicator(e.target)
      })
    })
  </script>
</body>

</html>
